import React, { PureComponent } from 'react';
import { TouchableWithoutFeedback, Keyboard } from 'react-native';
import dismissKeyboard from 'react-native/Libraries/Utilities/dismissKeyboard';

const DismissKeyboard = (WrappedComponent) =>
  class extends PureComponent {
    dismissKeyboard = () => {
      dismissKeyboard();
      Keyboard.dismiss();
    };
    render() {
      return (
        <TouchableWithoutFeedback
          style={{ flex: 1 }}
          onPress={this.dismissKeyboard}
        >
          <WrappedComponent {...this.props} />
        </TouchableWithoutFeedback>
      );
    }
  };

export default DismissKeyboard;
